package com.xiao.gulimall.product.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.gulimall.product.entity.CategoryEntity;
import com.xiao.gulimall.product.service.CategoryService;
import com.xiao.gulimall.product.vo.Category2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class CategoryWebController {

    @Autowired
    CategoryService categoryService;
    @RequestMapping(value = {"/","/index.html"})
    public String index(Model model){

        //查询所有的一级分类
        List<CategoryEntity> catId = categoryService.list(new QueryWrapper<CategoryEntity>().eq("parent_cid", 0));
        model.addAttribute("list",catId);
        return "index";
    }
    @ResponseBody
    @RequestMapping(value ={"/catalog"})
    public Map<Long, List<Category2Vo>> catelog(){
        Map <Long, List<Category2Vo>> map = categoryService.catelog();
        return map;
    }
}
